<template>
<van-form @submit="onSubmit">
    <van-field v-model="username" name="用户名" label="用户名" placeholder="用户名" :rules="[{ required: true, message: '请填写用户名' }]" />
    <van-field v-model="password" type="password" name="密码" label="密码" placeholder="密码" :rules="[{ required: true, message: '请填写密码' }]" />
    <div style="margin: 16px;">
        <!-- <van-button round block type="info" native-type="submit">
            提交
        </van-button> -->
    </div>
    <van-button type="primary" v-on:click='commit'>提交</van-button>
</van-form>
</template>

<script>
import {
    LOGIN
} from "@/api/login";
import request from '@/utils/request'
export default {
    data() {
        return {
            username: '',
            password: '',
        };
    },
    created() {

    },
    methods: {
        
        // onSubmit(values) {
             commit(values) {
            console.log('submit', values);
            const obj = {
                // account: 'hzq',
                // pwd: 'gzrd@123'
                  account: this.username,
                  pwd: this.password
            }

            //     // sessionStorage.setItem("token", res.data.posId);
            //     console.log(res)
            //     alert(this.$route.path)
            //     // let hostName = this.$route.query.redirect; // 获取域名
            //     // if (hostName === this.$url()) { // 判断如果域名是你项目域名，说明是从本网站内部跳转过来的，
            //     //     this.$router.go(-1); // 登录成功后，返回上次进入的页面；
            //     // } else {
            //     //     window.open(this.$url() + '/index'); // 若不是网站内部跳转过来的，登陆成功后进入网站首页
            //     // }
            // })
            LOGIN(obj).then(function (res) {
                    sessionStorage.setItem("account", res.data.loginId);
                    sessionStorage.setItem("posId", res.data.posId);
                    sessionStorage.setItem("admin", res.data.R_HW_ADMIN);
                    sessionStorage.setItem("token", res.data.token);
                    console.log(res);
                    if (res.code == 200) {
                      this.tiaozhuan()
                    }

                })
                .catch(function (error) {
                    console.log(error);
                });

        },
        tiaozhuan() {
            this.$router.push({
                path: "/index"
            })
            
        }
    }
};
</script>
